#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int binary_search(int a[],int z,int k)//二分查找
{
	int left = 0;
	int right = z-1;
	while (left <= right)
	{
		int mid = (right + left) / 2;
		if (a[mid] > k)
		{
			right = mid - 1;

		}
		else if (a[mid] < k)
		{
			left = mid + 1;
		
		}
		else
		{
			return mid;
		}
	}
	return 0;
}
int main()
{
	int arr[] = { 1,2,3,4,5,6,7,8,9,10 };
	int key = 6;
	int ze = sizeof (arr)/ sizeof arr[0];
	int mun = binary_search(arr,ze,key);
	if (mun != 0)
	{
		printf("ҵ%d\n", mun);
	}
	else
	{
		printf("Ҳ");
	}

	return 0;

}
